<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="110px">
      <el-form-item label="类型" prop="type">
        <el-select v-model="queryParams.type" placeholder="请选择类型" clearable >
          <el-option label="入金" :value="1" />
          <el-option label="提现" :value="2" />
          <el-option label="提现回退" :value="4" />
          <el-option label="对外转账" :value="3" />
          <el-option label="对外转账回退" :value="5" />
          <el-option label="扣除" :value="6" />
        </el-select>
      </el-form-item>
      <el-form-item label="变动时间">
        <el-date-picker clearable
            v-model="dateRange"
            type="daterange"
            range-separator="至"
            value-format="yyyy-MM-dd"
            :picker-options="pickerOptions"
            start-placeholder="开始日期" end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['ecs:balanceRecord:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="balanceRecordList">
      <el-table-column label="变动前金额" align="center" prop="beforeAmount" />
      <el-table-column label="变动后金额" align="center" prop="afterAmount" />
      <el-table-column label="变动金额" align="center" prop="changeAmount" />
      <el-table-column label="变动时间" align="center" prop="createTime" />
      <el-table-column label="类型" align="center" prop="type">
        <template slot-scope="scope">
          <span v-if="scope.row.type === 1">入金</span>
          <span v-else-if="scope.row.type === 2">提现</span>
          <span v-else-if="scope.row.type === 3">对外转账</span>
          <span v-else-if="scope.row.type === 4">提现回退</span>
          <span v-else-if="scope.row.type === 5">对外转账回退</span>
          <span v-else-if="scope.row.type === 6">扣除</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listBalanceRecord, getBalanceRecord, delBalanceRecord, addBalanceRecord, updateBalanceRecord } from "@/api/ecs/balanceRecord";

export default {
  name: "BalanceRecord",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      //日期范围
      dateRange: [],
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      // 余额记录表格数据
      balanceRecordList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        depositRecordId: null,
        separateAccountsId: null,
        splitId: null,
        roleType: null,
        beforeAmount: null,
        afterAmount: null,
        changeAmount: null,
        type: null,
      },

    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询余额记录列表 */
    getList() {
      this.loading = true;
      listBalanceRecord(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.balanceRecordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 导出按钮操作 */
    handleExport() {
      this.download('ecs/balanceRecord/export', {
        ...this.queryParams
      }, `余额记录_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
